#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
bool hasCycle(struct ListNode* head) {
    struct ListNode* m = head;
    struct ListNode* k = head;
    while (k && k->next)
    {
        m = m->next;
        k = k->next->next;

        if (k == m)
        {
            return true;
        }
    }
    return false;
}